/**************************************************************************
 * @name: DirDemo.c
 * @brief: 这是使用标准IO实现对linux系统下的目录文件访问的代码案例
 * @date: 2025/01/09
 * @author: boluzs@163.com
 * @note: None
 * @version: 1.0.0
 * @Copyright (c) 2025 by boluzs@163.com, All Rights Reserved.
 **************************************************************************/
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include <unistd.h>
#include <sys/stat.h>

#define DIR_PATH "/tmp/images/bmp321/"

int main(int argc, char const *argv[])
{
    // 1.需要打开的目录
    DIR *dir_p = opendir(DIR_PATH);
    // 2.切换工作目录
    int dir_d = chdir(DIR_PATH);
    // 3.读取目录文件中的目录项
    struct dirent *dirent_p = NULL;
    // 4.循环读取目录项
    while (dirent_p = readdir(dir_p))
    {
        struct stat *sb;
        stat(dirent_p->d_name, sb);
        if (dirent_p->d_name[0] != '.' && (sb->st_mode & __S_IFMT) == __S_IFREG)
        {
            printf("文件名:%s, 文件类型:%d\n", dirent_p->d_name, sb->st_mode);
        }
    }
    return 0;
}
